package com.syg.generator.model;


import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ColumnModel {
    private String columnName = "";
    private String humpColumnName = "";
    private String comment = "";
    private String colType = "";
    private String colDbType = "";
    private boolean isPK = false;
    private long length = 0L;
    private int precision = 0;
    private int scale = 0;
    private int autoGen = 0;
    private boolean isNotNull = false;
    private String displayDbType = "";
    private String jdbcType;
    private boolean haveJdbcType = false;
    private static Map<String, String> typeMap = new ConcurrentHashMap();

    public ColumnModel() {
    }

    public String getColumnName() {
        return this.columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getHumpColumnName() {
        return this.humpColumnName;
    }

    public void setHumpColumnName(String humpColumnName) {
        this.humpColumnName = humpColumnName;
    }

    public String getComment() {
        return this.comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public String getColType() {
        return this.colType;
    }

    public void setColType(String colType) {
        this.colType = colType;
        this.jdbcType = (String)typeMap.get(colType);
        if (null == this.jdbcType || "".equals(this.jdbcType)) {
            this.haveJdbcType = true;
        }

    }

    public String getColDbType() {
        return this.colDbType;
    }

    public void setColDbType(String colDbType) {
        this.colDbType = colDbType;
    }

    public boolean getIsPK() {
        return this.isPK;
    }

    public void setIsPK(boolean isPK) {
        this.isPK = isPK;
    }

    public long getLength() {
        return this.length;
    }

    public void setLength(long length) {
        this.length = length;
    }

    public int getPrecision() {
        return this.precision;
    }

    public void setPrecision(int precision) {
        this.precision = precision;
    }

    public int getScale() {
        return this.scale;
    }

    public void setScale(int scale) {
        this.scale = scale;
    }

    public int getAutoGen() {
        return this.autoGen;
    }

    public void setAutoGen(int autoGen) {
        this.autoGen = autoGen;
    }

    public boolean getIsNotNull() {
        return this.isNotNull;
    }

    public void setIsNotNull(boolean isNotNull) {
        this.isNotNull = isNotNull;
    }

    public String getDisplayDbType() {
        return this.displayDbType;
    }

    public void setDisplayDbType(String displayDbType) {
        this.displayDbType = displayDbType;
    }

    public String getJdbcType() {
        return this.jdbcType;
    }

    public void setJdbcType(String jdbcType) {
        this.jdbcType = jdbcType;
    }

    public boolean isHaveJdbcType() {
        return this.haveJdbcType;
    }

    public void setHaveJdbcType(boolean haveJdbcType) {
        this.haveJdbcType = haveJdbcType;
    }

    @Override
    public String toString() {
        return "ColumnModel [columnName=" + this.columnName + ", comment=" + this.comment + ", colType=" + this.colType + ", colDbType=" + this.colDbType + ", isPK=" + this.isPK + ", length=" + this.length + ", precision=" + this.precision + ", scale=" + this.scale + ", autoGen=" + this.autoGen + ", isNotNull=" + this.isNotNull + ", displayDbType=" + this.displayDbType + ", jdbcType=" + this.jdbcType + ", haveJdbcType=" + this.haveJdbcType + "]";
    }

    static {
        typeMap.put("java.lang.String", "VARCHAR");
        typeMap.put("String", "VARCHAR");
        typeMap.put("java.math.BigDecimal", "DECIMAL");
        typeMap.put("BigDecimal", "DECIMAL");
        typeMap.put("Boolean", "BOOLEAN");
        typeMap.put("boolean", "BOOLEAN");
        typeMap.put("byte", "TINYINT");
        typeMap.put("Byte", "TINYINT");
        typeMap.put("short", "SMALLINT");
        typeMap.put("Short", "SMALLINT");
        typeMap.put("int", "INTEGER");
        typeMap.put("Integer", "INTEGER");
        typeMap.put("long", "BIGINT");
        typeMap.put("Long", "BIGINT");
        typeMap.put("float", "REAL");
        typeMap.put("Float", "REAL");
        typeMap.put("double", "FLOAT");
        typeMap.put("Double", "FLOAT");
        typeMap.put("byte[]", "VARBINARY");
        typeMap.put("java.util.Date", "TIMESTAMP");
        typeMap.put("java.sql.Date", "TIMESTAMP");
        typeMap.put("java.sql.Time", "TIME");
        typeMap.put("java.sql.Timestamp", "TIMESTAMP");
        typeMap.put("Clob", "CLOB");
        typeMap.put("Blob", "BLOB");
        typeMap.put("Array", "ARRAY");
    }
}
